import argparse

from oneconvert.converter import default


def do_convert(args):
    default.DefaultConverter(args.input_uri, args.output_uri,
                             input_format=args.input_format,
                             output_format=args.output_format).convert()


def add_convert_param_parser(subparsers):
    parser_convert = subparsers.add_parser(
        "convert",
        help="Convert DataSource",
    )
    parser_convert.set_defaults(func=do_convert)

    input_param_group = parser_convert.add_argument_group("input config")
    input_param_group.add_argument(
        "-in", "--input",
        type=str,
        help="input resource URI",
        required=True,
        dest='input_uri')
    input_param_group.add_argument(
        "--in-format",
        type=str,
        help="input resource format",
        required=False,
        dest='input_format'
    )

    output_param_group = parser_convert.add_argument_group("output config")
    output_param_group.add_argument(
        "-out", "--output",
        type=str,
        help="output resource uri",
        required=True,
        dest='output_uri')
    output_param_group.add_argument(
        "--out-format",
        type=str,
        help="output resource format",
        required=False,
        dest='output_format'
    )


def main():
    parser = argparse.ArgumentParser(
        description="Easy Convert",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter
    )

    subparsers = parser.add_subparsers(
        dest="command",
        required=True,
        help="Available Command",
    )
    add_convert_param_parser(subparsers)

    args = parser.parse_args()
    args.func(args)


if __name__ == '__main__':
    main()
